<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('职称申报列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>竞聘等级：</label>
                                <select name="competeLevel" th:with="type=${@dict.getType('basic_post_title')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>提交状态：</label>
                                <select name="submitFlag">
                                    <option value="">所有</option>
                                    <option value="0">未提交</option>
                                    <option value="1">已提交</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="record:compete:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="edit()" shiro:hasPermission="record:compete:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="remove()" shiro:hasPermission="record:compete:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning multiple disabled" onclick="submit()" shiro:hasPermission="record:compete:submit">
                    <i class="fa fa-print"></i> 提交
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "record/compete";

        var levels = [[${@dict.getType('basic_post_title')}]];
        var datas = [[${@dict.getType('sys_yes_no')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "职称竞聘",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'competeId',
                    title: '申报id',
                    visible: false
                },
                {
                    field: 'competeLevel',
                    title: '竞聘级别',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(levels, value);
                    }
                },
                {
                    visible: [[${isAdmin}]],
                    field: 'userName',
                    title: '姓名'
                },
                {
                    visible: [[${isAdmin}]],
                    field: 'idCard',
                    title: '身份证号'
                },
                {
                    field: 'postName',
                    title: '现职务资格'
                },
                {
                    field: 'obtainLevel',
                    title: '现资格等级',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(levels, value);
                    }
                },
                {
                    field: 'obtainTime',
                    title: '现资格取得时间'
                },
                {
                    field: 'postLevel',
                    title: '现聘任等级',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(levels, value);
                    }
                },
                {
                    field: 'engageTime',
                    title: '现资格聘任时间'
                },
                {
                    field: 'plurality',
                    title: '学术兼职',
                },
                {
                    field: 'isTeacher',
                    title: '是否担任过带教老师或教学秘书',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'isFarmer',
                    title: '是否参加过支农、第一村医等活动',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'isStandard',
                    title: '继续教育及继续医学教育学分是否达到合格标准',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'isFailure',
                    title: '是否发生过医疗事故',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'submitFlag',
                    title: '提交状态',
                    formatter: function(value, row, index) {
                        if(value === '1') {
                            return '已提交';
                        } else {
                            return '未提交';
                        }
                    }
                },
                {
                    field: 'submitTime',
                    title: '提交时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
            };
            $.table.init(options);
        });

        function edit(){
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if(row.submitFlag == '1'){
                $.modal.alertError("已提交的职称竞聘不能修改");
                return;
            }
            $.operate.editFull();
        }

        function remove(){
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if (row.submitFlag == '1') {
                $.modal.alertError("已提交的职称竞聘不能删除");
                return;
            }
            $.operate.removeAll();
        }

        function submit(){
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if (row.submitFlag == '1') {
                $.modal.alertError("已提交的职称竞聘不能再次提交");
                return;
            }
            $.ajax({
                type: "post",
                url: prefix + "/submit",
                dataType: "json",
                data: {"competeId" : row.competeId},
                success: function(r) {
                    if (r.code == web_status.SUCCESS) {
                        $.modal.msgSuccess("提交成功");
                        $.table.refresh();
                    } else {
                        $.modal.msgError(r.msg);
                    }
                    $.modal.closeLoading();
                }
            });
        }
    </script>
</body>
</html>